//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef ___DRVPUB_H__
#define ___DRVPUB_H__

// GPIO
#define GPIO_PIN_IN 0
#define GPIO_PIN_OUT    1

#define GPIO_AS_GPIO    0
#define GPIO_AS_AF1 1
#define GPIO_AS_AF2 2
#define GPIO_AS_AF3 3

// Flags for Driver buffer alloc
#define DRVBUF_SPEED_FAST   0x1
#define DEVBUF_REALLOC_COPY 0x2

//#define DRV_ASSERT_ENABLE // It should be not defined in the retail product
#ifdef DRV_ASSERT_ENABLE
INLINE void _DrvAssert(const char *szExpr, const char *szFile, int nLine)
{
    kprintf("Assertion failed: %s, file: %s, line: %d\n",
            szExpr, szFile, nLine);
    DebugBreak();
}
#define Drv_Assert(expr) \
    ((void)((expr) || (_DrvAssert(#expr, __FILE__, __LINE__), FALSE)))
#else
#define Drv_Assert(expr)
#endif

/* Defined for Postern*/
typedef  void (*FuncCell)(int argc, BYTE **argv);
typedef struct _PosternFunc {
    FuncCell PosternCell;
    int Argc;
    BYTE **Argv;
    char* CmdDescriptor;
    char* CmdSample;
}PosternFunc;

EXTERN_C ECode __cdecl InitPostern();
EXTERN_C BOOL __cdecl AddPosternCell( FuncCell func,
                                      int argc,
                                      BYTE **argv,
                                      char* CmdDescriptor,
                                      char* CmdSample );


EXTERN_C int Drv_DmaInstall(unsigned int priority, void *Device, void * Handler);
EXTERN_C BOOL Drv_GpioInstall(unsigned int Pin, void *Device, void * Handler);

EXTERN_C ECode Drv_InitBuffer();
EXTERN_C void * Drv_AllocBuffer(unsigned int uPages, unsigned int uFlag);
EXTERN_C void * Drv_ReallocBuffer(void * VirtAddr, unsigned int uOldPages,
    unsigned int uNewPages, unsigned int uFlag);
EXTERN_C void Drv_FreeBuffer(void * VirtAddr, unsigned int uPages);
EXTERN_C unsigned int Drv_GetBufferPhysicalAddress(void * VirtAddr);

void Gpio_SetDir(int gpio_num, int direction);
void Gpio_SetAFR(int gpio_num, int function);
void Gpio_SetOutLow(int gpio_num);
void Gpio_SetOutHigh(int gpio_num);

#endif // ___DRVPUB_H__
